package java2020spring;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.*;
public class CalculatorJPanel extends JFrame {
	public CalculatorJPanel(){
		Container c = getContentPane();
		c.setLayout(new GridLayout(2, 1, 10, 10));
		//将容器设置为2行1列的网格布局，组建间隔10像素
		JPanel p1 = new JPanel(new GridLayout(1,1,10,10));
		JPanel p2 = new JPanel(new GridLayout(1,1,10,10));
		JPanel p3 = new JPanel(new GridLayout(4,3,10,10));
		JPanel p4 = new JPanel(new GridLayout(4,2,10,10));
		p1.setBorder(BorderFactory.createTitledBorder("运算区域"));
		p2.setBorder(BorderFactory.createTitledBorder("结果区域"));
		p3.setBorder(BorderFactory.createTitledBorder("数字区域"));
		p4.setBorder(BorderFactory.createTitledBorder("符号区域"));
		JButton b1 = new JButton("1");
		JButton b2 = new JButton("2");
		JButton b3 = new JButton("3");
		JButton b4 = new JButton("4");
		JButton b5 = new JButton("5");
		JButton b6 = new JButton("6");
		JButton b7 = new JButton("7");
		JButton b8 = new JButton("8");
		JButton b9 = new JButton("9");
		JButton b0 = new JButton("0");
		JButton b00 = new JButton("00");
		JButton bPoint = new JButton(".");
		JButton bPlus = new JButton("+");
		JButton bAC = new JButton("AC");
		JButton bMinus = new JButton("-");
		JButton bZhengFu = new JButton("+/-");
		JButton bCheng = new JButton("x");
		JButton bQuYu = new JButton("%");
		JButton bChu = new JButton("÷");
		JButton bEqual = new JButton("=");
		p3.add(b7);
		p3.add(b8);
		p3.add(b9);
		p3.add(b4);
		p3.add(b5);
		p3.add(b6);
		p3.add(b1);
		p3.add(b2);
		p3.add(b3);
		p3.add(b0);
		p3.add(b00);
		p3.add(bPoint);
		p4.add(bPlus);
		p4.add(bAC);
		p4.add(bMinus);
		p4.add(bZhengFu);
		p4.add(bCheng);
		p4.add(bQuYu);
		p4.add(bChu);
		p4.add(bEqual);
		c.add(p1);
		c.add(p2);
		c.add(p3);
		c.add(p4);
		setTitle("FishCalculator");
		setSize(500,300);
		setVisible(true);
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);	
	}
	public static void main(String args[]) {
		new CalculatorJPanel();
	}
}